package com.example.demo.dto;

import com.example.demo.entity.TaskApprovalStatus;
import java.time.LocalDateTime;


public class TaskApprovalStatusDTO {
    private Long id;                    // 主键ID
    private Long taskFlowId;            // 关联task_flow表的ID
    private String taskFlowName;        // 任务流程名称
    private Long nodeId;                // 节点ID（process_node.id）
    private String nodeName;            // 节点名称
    private Integer status;             // 状态：0=待处理,1=处理中,2=已通过,3=已拒绝,4=已跳过
    private String statusText;          // 状态文本描述
    private Long approverId;            // 审批人ID
    private String approverName;        // 审批人姓名
    private String comment;             // 审批意见
    private LocalDateTime startTime;    // 节点开始时间
    private LocalDateTime endTime;      // 节点完成时间
    private LocalDateTime createdAt;    // 创建时间
    private LocalDateTime updatedAt;    // 更新时间
    private Long taskId;                // 任务ID
    private Long dataSourceId;          // 数据源ID
    private Long flowId;                // 流程ID
    private String flowName;            // 流程名称
    private String rawData;             // 从数据源抓取的原始数据，JSON格式
    private Integer nodeOrder;          // 节点顺序

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getTaskFlowId() {
        return taskFlowId;
    }

    public void setTaskFlowId(Long taskFlowId) {
        this.taskFlowId = taskFlowId;
    }

    public String getTaskFlowName() {
        return taskFlowName;
    }

    public void setTaskFlowName(String taskFlowName) {
        this.taskFlowName = taskFlowName;
    }

    public Long getNodeId() {
        return nodeId;
    }

    public void setNodeId(Long nodeId) {
        this.nodeId = nodeId;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStatusText() {
        return statusText;
    }

    public void setStatusText(String statusText) {
        this.statusText = statusText;
    }

    public String getApproverName() {
        return approverName;
    }

    public void setApproverName(String approverName) {
        this.approverName = approverName;
    }

    public Long getApproverId() {
        return approverId;
    }

    public void setApproverId(Long approverId) {
        this.approverId = approverId;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Long getDataSourceId() {
        return dataSourceId;
    }

    public void setDataSourceId(Long dataSourceId) {
        this.dataSourceId = dataSourceId;
    }

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public Long getFlowId() {
        return flowId;
    }

    public void setFlowId(Long flowId) {
        this.flowId = flowId;
    }

    public String getFlowName() {
        return flowName;
    }

    public void setFlowName(String flowName) {
        this.flowName = flowName;
    }

    public String getRawData() {
        return rawData;
    }

    public void setRawData(String rawData) {
        this.rawData = rawData;
    }

    public Integer getNodeOrder() {
        return nodeOrder;
    }

    public void setNodeOrder(Integer nodeOrder) {
        this.nodeOrder = nodeOrder;
    }

    // 从实体类转换为DTO
    public static TaskApprovalStatusDTO fromEntity(TaskApprovalStatus entity) {
        TaskApprovalStatusDTO dto = new TaskApprovalStatusDTO();
        dto.setId(entity.getId());
        dto.setTaskFlowId(entity.getTaskFlowId());
        dto.setNodeId(entity.getNodeId());
        dto.setStatus(entity.getStatus());
        dto.setStatusText(getStatusText(entity.getStatus()));
        dto.setApproverId(entity.getApproverId());
        dto.setApproverName(entity.getApproverName());
        dto.setComment(entity.getComment());
        dto.setStartTime(entity.getStartTime());
        dto.setEndTime(entity.getEndTime());
        dto.setCreatedAt(entity.getCreatedAt());
        dto.setUpdatedAt(entity.getUpdatedAt());
        dto.setTaskId(entity.getTaskId());
        dto.setDataSourceId(entity.getDataSourceId());
        dto.setFlowId(entity.getFlowId());
        dto.setNodeOrder(entity.getNodeOrder());
        // 设置默认的rawData，用于测试
        dto.setRawData("{\"test\": \"default-data\"}");
        return dto;
    }

    // 从DTO转换为实体类
    public TaskApprovalStatus toEntity() {
        TaskApprovalStatus entity = new TaskApprovalStatus();
        entity.setId(this.getId());
        entity.setTaskFlowId(this.getTaskFlowId());
        entity.setNodeId(this.getNodeId());
        entity.setStatus(this.getStatus());
        entity.setApproverId(this.getApproverId());
        entity.setApproverName(this.getApproverName());
        entity.setComment(this.getComment());
        entity.setStartTime(this.getStartTime());
        entity.setEndTime(this.getEndTime());
        entity.setCreatedAt(this.getCreatedAt());
        entity.setUpdatedAt(this.getUpdatedAt());
        entity.setTaskId(this.getTaskId());
        entity.setDataSourceId(this.getDataSourceId());
        entity.setFlowId(this.getFlowId());
        return entity;
    }

    // 状态文本映射
    private static String getStatusText(Integer status) {
        if (status == null) return "未知";
        switch (status) {
            case 0: return "待处理";
            case 1: return "处理中";
            case 2: return "已通过";
            case 3: return "已拒绝";
            case 4: return "已跳过";
            default: return "未知";
        }
    }
}